//============================================================================
// Name        : ttt.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

#include "gtest/gtest.h"
#include "HangManGame.h"
#include "Action.h"

class SimAction : public Action
{
public:
	bool _winHandleCalled;
	bool _loseHandleCalled;

public:
	SimAction() {
		_winHandleCalled = false;
		_loseHandleCalled = false;
	}
	virtual void winHandle()
	{
		_winHandleCalled = true;
	}
	virtual void loseHandle()
	{
		_loseHandleCalled = true;
	}
};
//
//todo:
//1, leftTries done
//2, problem  done
//3, solution  done
//4, used  done
//5, game win
//6, game lose

class HangManTest : public testing::Test
{
public:
	virtual void SetUp()
	{
		_act = new SimAction();
		_hangMan = new HangManGame("bear", _act);
	}
	virtual void TearDown()
	{
		delete _hangMan;
		delete _act;
	}
	HangManGame* _hangMan;
	SimAction* _act;
};

TEST_F(HangManTest, try_times_should_be_12_when_init_game)
{
	ASSERT_EQ(12, _hangMan->getLeftTries());
}

TEST_F(HangManTest, try_times_should_be_12_when_try_char_contained)
{
	_hangMan->tryChar('b');
	ASSERT_EQ(12, _hangMan->getLeftTries());
}

TEST_F(HangManTest, try_times_should_be_11_when_try_char_not_contained)
{
	_hangMan->tryChar('c');
	ASSERT_EQ(11, _hangMan->getLeftTries());
}

TEST_F(HangManTest, try_times_should_be_11_when_try_vowels_char_that_contained)
{
	_hangMan->tryChar('a');
	ASSERT_EQ(11, _hangMan->getLeftTries());
}

TEST_F(HangManTest, try_times_should_be_11_when_try_char_that_has_tried)
{
	_hangMan->tryChar('b');
	_hangMan->tryChar('b');
	ASSERT_EQ(11, _hangMan->getLeftTries());
}

TEST_F(HangManTest, used_chars_should_be_aeiou_when_init_game)
{
	ASSERT_STREQ("aeiou", _hangMan->getUsedChars());
}

TEST_F(HangManTest, used_chars_should_be_aeiou_when_try_vowels_again)
{
	_hangMan->tryChar('a');
	ASSERT_STREQ("aeiou", _hangMan->getUsedChars());
}

TEST_F(HangManTest, used_chars_should_be_aeioub_when_try_b)
{
	_hangMan->tryChar('b');
	ASSERT_STREQ("aeioub", _hangMan->getUsedChars());
}

TEST_F(HangManTest, used_chars_should_be_aeioub_when_try_b_two_times)
{
	_hangMan->tryChar('b');
	_hangMan->tryChar('b');
	ASSERT_STREQ("aeioub", _hangMan->getUsedChars());
}

TEST_F(HangManTest, test_problem_chars_when_init_game)
{
	ASSERT_STREQ("_ea_", _hangMan->getProblem());
}

TEST(HangManProblemTest, test_problem_chars_given_another_result)
{
	HangManGame game("david", new SimAction());
	ASSERT_STREQ("_a_i_", game.getProblem());
}

TEST_F(HangManTest, test_problem_when_try_a_right_ch)
{
	_hangMan->tryChar('b');
	ASSERT_STREQ("bea_", _hangMan->getProblem());
	_hangMan->tryChar('r');
	ASSERT_STREQ("bear", _hangMan->getProblem());
}

TEST_F(HangManTest, test_win)
{
	_hangMan->tryChar('b');
	_hangMan->tryChar('r');
	ASSERT_TRUE(_act->_winHandleCalled);
}

TEST_F(HangManTest, test_lose)
{
	_hangMan->tryChar('b');
	_hangMan->tryChar('t');
	_hangMan->tryChar('t');
	_hangMan->tryChar('t');
	_hangMan->tryChar('t');
	_hangMan->tryChar('t');
	_hangMan->tryChar('t');
	_hangMan->tryChar('t');
	_hangMan->tryChar('t');
	_hangMan->tryChar('t');
	_hangMan->tryChar('t');
	_hangMan->tryChar('t');
	_hangMan->tryChar('t');
	ASSERT_TRUE(_act->_winHandleCalled);
}


int main(int argc, char **argv)
{
	cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
